package com.francis.spring.framework.aop.aspect;

import com.francis.spring.framework.aop.intercept.FrancisMethodInterceptor;
import com.francis.spring.framework.aop.intercept.FrancisMethodInvocation;

import java.lang.reflect.Method;

/**
 * @Author Francis
 * @Date 2020/11/22 22:33
 * @Version 1.0
 * @Description:
 */
public class FrancisAfterReturningAdviceInterceptor extends FrancisAbstractAspectAdvice implements FrancisAdvice, FrancisMethodInterceptor {

    private FrancisJoinPoint joinPoint;

    public FrancisAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    @Override
    public Object invoke(FrancisMethodInvocation mi) throws Throwable {
        Object retVal = mi.proceed();
        this.joinPoint = mi;
        this.afterReturning(retVal,mi.getMethod(),mi.getArguments(),mi.getThis());
        return retVal;
    }

    private void afterReturning(Object retVal, Method method, Object[] arguments, Object aThis) throws Throwable {
        super.invokeAdviceMethod(this.joinPoint,retVal,null);
    }
}
